package com.canin.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Map;

import com.canin.model.SBed;
import com.canin.model.SBowl;
import com.canin.model.SCollar;
import com.canin.model.SKennel;
import com.canin.model.SLeashes;
import com.canin.model.SToothbrush;
import com.canin.model.SToy;
import com.canin.util.CaninUtil;

public class SEquipmentDAO
{
	private Connection conn = null;
	private Map<String, String> sizes = CaninUtil.initializeSizes();
	private Map<Integer, String> neckType = CaninUtil.initializeNeckType();
	private Map<Integer, String> toyType = CaninUtil.initializeToyType();

	public SEquipmentDAO(Connection conn)
	{
		this.conn = conn;
	}

	public ArrayList<SBed> getSBedAll() throws Exception
	{
		ArrayList<SBed> sbedList = new ArrayList<SBed>();

		String sql = "select * from bed_standard_size";
		PreparedStatement ps = conn.prepareStatement(sql);

		ResultSet rs = ps.executeQuery();

		while (rs.next())
		{
			SBed sbed = new SBed();
			
			sbed.setId( rs.getInt( "ID" ) );
			sbed.setStandardSize( rs.getString( "standard_size" ) );
			sbed.setMinWidht( rs.getInt( "min_width" ) );
			sbed.setMaxWidht( rs.getInt( "max_width" ) );
			sbed.setMinLength( rs.getInt( "min_length" ) );
			sbed.setMaxLength( rs.getInt( "max_length" ) );
			
			sbed.setSizeToDisplay( sizes.get( sbed.getStandardSize() ) );
			sbed.setWeightToDisplay( sbed.getMinWidht() + " - " + sbed.getMaxWidht() );
			sbed.setLengthToDisplay( sbed.getMinLength() + " - " + sbed.getMaxLength() );
			
			sbedList.add( sbed );
		}

		rs.close();
		ps.close();

		return sbedList;
	}
	
	public SBed getSBedDetail( String sbedSize ) throws SQLException
	{
		SBed sbed = new SBed();

		String sql = "SELECT * FROM bed_standard_size where standard_size=?";
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, sbedSize);

		ResultSet rs = ps.executeQuery();

		while (rs.next())
		{
			sbed.setId( rs.getInt( "ID" ) );
			sbed.setStandardSize( rs.getString( "standard_size" ) );
			sbed.setMinWidht( rs.getInt( "min_width" ) );
			sbed.setMaxWidht( rs.getInt( "max_width" ) );
			sbed.setMinLength( rs.getInt( "min_length" ) );
			sbed.setMaxLength( rs.getInt( "max_length" ) );
			
			sbed.setSizeToDisplay( sizes.get( sbed.getStandardSize() ) );
			sbed.setWeightToDisplay( sbed.getMinWidht() + " - " + sbed.getMaxWidht() );
			sbed.setLengthToDisplay( sbed.getMinLength() + " - " + sbed.getMaxLength() );
			sbed.setSizes( sbed.getStandardSize() );
		}

		rs.close();
		ps.close();
		
		return sbed;
	}
	
	public boolean updateSBedDetail( SBed sbed ) throws SQLException
	{
		String sql = "UPDATE bed_standard_size SET min_width=?, max_width=?, min_length=?, max_length=? " +
				"WHERE id=?";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setInt(1, sbed.getMinWidht());
		ps.setInt(2, sbed.getMaxWidht());
		ps.setInt(3, sbed.getMinLength());
		ps.setInt(4, sbed.getMaxLength());
		ps.setInt(5, sbed.getId());

		ps.executeUpdate();
		ps.close();
		
		conn.close();
		
		return true;
	}

	public ArrayList<SBowl> getSBowlAll() throws Exception
	{
		ArrayList<SBowl> sbowlList = new ArrayList<SBowl>();

		String sql = "select * from bowl_standard_size";
		PreparedStatement ps = conn.prepareStatement(sql);

		ResultSet rs = ps.executeQuery();

		while (rs.next())
		{
			SBowl sbowl = new SBowl();
			
			sbowl.setId( rs.getInt( "ID" ) );
			sbowl.setStandardSize( rs.getString( "standard_size" ) );
			sbowl.setMinDiameter( rs.getInt( "min_diameter" ) );
			sbowl.setMaxDiameter( rs.getInt( "max_diameter" ) );
			sbowl.setMinHeight( rs.getInt( "min_height" ) );
			sbowl.setMaxHeight( rs.getInt( "max_height" ) );
			
			sbowl.setSizeToDisplay( sizes.get( sbowl.getStandardSize() ) );
			sbowl.setDiameterToDisplay( sbowl.getMinDiameter() + " - " + sbowl.getMaxDiameter() );
			sbowl.setHeightToDisplay( sbowl.getMinHeight() + " - " + sbowl.getMaxHeight() );
			
			sbowlList.add( sbowl );
		}

		rs.close();
		ps.close();

		return sbowlList;
	}
	
	public SBowl getSBowlDetail( String size ) throws SQLException
	{
		SBowl sbowl = new SBowl();

		String sql = "SELECT * FROM bowl_standard_size where standard_size=?";
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, size);

		ResultSet rs = ps.executeQuery();

		while (rs.next())
		{
			sbowl.setId( rs.getInt( "ID" ) );
			sbowl.setStandardSize( rs.getString( "standard_size" ) );
			sbowl.setMinDiameter( rs.getInt( "min_diameter" ) );
			sbowl.setMaxDiameter( rs.getInt( "max_diameter" ) );
			sbowl.setMinHeight( rs.getInt( "min_height" ) );
			sbowl.setMaxHeight( rs.getInt( "max_height" ) );
			
			sbowl.setSizeToDisplay( sizes.get( sbowl.getStandardSize() ) );
			sbowl.setDiameterToDisplay( sbowl.getMinDiameter() + " - " + sbowl.getMaxDiameter() );
			sbowl.setHeightToDisplay( sbowl.getMinHeight() + " - " + sbowl.getMaxHeight() );
			sbowl.setSizes( sbowl.getStandardSize() );
		}

		rs.close();
		ps.close();
		
		return sbowl;
	}
	
	public boolean updateSBowlDetail( SBowl sbowl ) throws SQLException
	{
		String sql = "UPDATE bowl_standard_size SET min_diameter=?, max_diameter=?, min_height=?, max_height=? " +
				"WHERE id=?";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setInt(1, sbowl.getMinDiameter());
		ps.setInt(2, sbowl.getMaxDiameter());
		ps.setInt(3, sbowl.getMinHeight());
		ps.setInt(4, sbowl.getMaxHeight());
		ps.setInt(5, sbowl.getId());

		ps.executeUpdate();
		ps.close();
		
		conn.close();
		
		return true;
	}

	public ArrayList<SCollar> getSCollarAll() throws Exception
	{
		ArrayList<SCollar> scollarList = new ArrayList<SCollar>();

		String sql = "select * from collar_standard_size";
		PreparedStatement ps = conn.prepareStatement(sql);

		ResultSet rs = ps.executeQuery();

		while (rs.next())
		{
			SCollar scollar = new SCollar();
			
			scollar.setId( rs.getInt( "ID" ) );
			scollar.setStandardSize( rs.getString( "standard_size" ) );
			scollar.setSizeType( rs.getInt( "size_type" ) );
			scollar.setMinWidht( rs.getInt( "min_width" ) );
			scollar.setMaxWidht( rs.getInt( "max_width" ) );
			scollar.setMinLength( rs.getInt( "min_length" ) );
			scollar.setMaxLength( rs.getInt( "max_length" ) );
			
			scollar.setSizeToDisplay( sizes.get( scollar.getStandardSize() ) );
			scollar.setTypeToDisplay( neckType.get( scollar.getSizeType()) );
			scollar.setWeightToDisplay( scollar.getMinWidht() + " - " + scollar.getMaxWidht() );
			scollar.setLengthToDisplay( scollar.getMinLength() + " - " + scollar.getMaxLength() );
			
			scollarList.add( scollar );
		}

		rs.close();
		ps.close();

		return scollarList;
	}
	
	public SCollar getSCollarDetail( int type, String size ) throws SQLException
	{
		SCollar scollar = new SCollar();

		String sql = "SELECT * FROM collar_standard_size where standard_size=? and size_type=?;";
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, size);
		ps.setInt(2, type);

		ResultSet rs = ps.executeQuery();

		while (rs.next())
		{
			scollar.setId( rs.getInt( "ID" ) );
			scollar.setStandardSize( rs.getString( "standard_size" ) );
			scollar.setSizeType( rs.getInt( "size_type" ) );
			scollar.setMinWidht( rs.getInt( "min_width" ) );
			scollar.setMaxWidht( rs.getInt( "max_width" ) );
			scollar.setMinLength( rs.getInt( "min_length" ) );
			scollar.setMaxLength( rs.getInt( "max_length" ) );
			
			scollar.setSizes( scollar.getStandardSize() );
			scollar.setTypes( scollar.getSizeType() );
			
			scollar.setSizeToDisplay( sizes.get( scollar.getStandardSize() ) );
			scollar.setTypeToDisplay( neckType.get( scollar.getSizeType()) );
			scollar.setWeightToDisplay( scollar.getMinWidht() + " - " + scollar.getMaxWidht() );
			scollar.setLengthToDisplay( scollar.getMinLength() + " - " + scollar.getMaxLength() );
		}

		rs.close();
		ps.close();
		
		return scollar;
	}
	
	public void updateSCollarDetail( SCollar scollar ) throws SQLException
	{
		String sql = "UPDATE collar_standard_size SET min_width=?, max_width=?, min_length=?, max_length=? " +
				"WHERE id=?";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setInt(1, scollar.getMinWidht());
		ps.setInt(2, scollar.getMaxWidht());
		ps.setInt(3, scollar.getMinLength());
		ps.setInt(4, scollar.getMaxLength());
		ps.setInt(5, scollar.getId());

		ps.executeUpdate();
		ps.close();
		
		conn.close();
	}

	public ArrayList<SKennel> getSKennelAll() throws Exception
	{
		ArrayList<SKennel> skennelList = new ArrayList<SKennel>();

		String sql = "select * from kennel_standard_size";
		PreparedStatement ps = conn.prepareStatement(sql);

		ResultSet rs = ps.executeQuery();

		while (rs.next())
		{
			SKennel skennel = new SKennel();
			
			skennel.setId( rs.getInt( "ID" ) );
			skennel.setStandardSize( rs.getString( "standard_size" ) );
			skennel.setMinWidht( rs.getInt( "min_width" ) );
			skennel.setMaxWidht( rs.getInt( "max_width" ) );
			skennel.setMinLength( rs.getInt( "min_length" ) );
			skennel.setMaxLength( rs.getInt( "max_length" ) );
			skennel.setMinHeight( rs.getInt( "min_height" ) );
			skennel.setMaxHeight( rs.getInt( "max_height" ) );
			
			skennel.setSizeToDisplay( sizes.get( skennel.getStandardSize() ) );
			skennel.setWidhtToDisplay( skennel.getMinWidht() + " - " + skennel.getMaxWidht() );
			skennel.setLengthToDisplay( skennel.getMinLength() + " - " + skennel.getMaxLength() );
			skennel.setHeightToDisplay( skennel.getMinHeight() + " - " + skennel.getMaxHeight() );
			
			skennelList.add( skennel );
		}

		rs.close();
		ps.close();

		return skennelList;
	}
	
	public SKennel getSKennelDetail( String skennelSize ) throws SQLException
	{
		SKennel skennel = new SKennel();

		String sql = "SELECT * FROM kennel_standard_size where standard_size=?";
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, skennelSize);

		ResultSet rs = ps.executeQuery();

		while (rs.next())
		{
			skennel.setId( rs.getInt( "ID" ) );
			skennel.setStandardSize( rs.getString( "standard_size" ) );
			skennel.setMinWidht( rs.getInt( "min_width" ) );
			skennel.setMaxWidht( rs.getInt( "max_width" ) );
			skennel.setMinLength( rs.getInt( "min_length" ) );
			skennel.setMaxLength( rs.getInt( "max_length" ) );
			skennel.setMinHeight( rs.getInt( "min_height" ) );
			skennel.setMaxHeight( rs.getInt( "max_height" ) );
			
			skennel.setSizeToDisplay( sizes.get( skennel.getStandardSize() ) );
			skennel.setWidhtToDisplay( skennel.getMinWidht() + " - " + skennel.getMaxWidht() );
			skennel.setLengthToDisplay( skennel.getMinLength() + " - " + skennel.getMaxLength() );
			skennel.setHeightToDisplay( skennel.getMinHeight() + " - " + skennel.getMaxHeight() );
			skennel.setSizes( skennel.getStandardSize() );
		}

		rs.close();
		ps.close();
		
		return skennel;
	}
	
	public void updateSKennelDetail( SKennel skennel ) throws SQLException
	{
		String sql = "UPDATE kennel_standard_size SET min_width=?, max_width=?, " +
				"min_length=?, max_length=?, min_height=?, max_height=? " +
				"WHERE id=?";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setInt(1, skennel.getMinWidht());
		ps.setInt(2, skennel.getMaxWidht());
		ps.setInt(3, skennel.getMinLength());
		ps.setInt(4, skennel.getMaxLength());
		ps.setInt(5, skennel.getMinHeight());
		ps.setInt(6, skennel.getMaxHeight());
		ps.setInt(7, skennel.getId());

		ps.executeUpdate();
		ps.close();
		
		conn.close();
	}

	public ArrayList<SLeashes> getSLeashesAll() throws Exception
	{
		ArrayList<SLeashes> sleashesList = new ArrayList<SLeashes>();

		String sql = "select * from leashes_standard_size";
		PreparedStatement ps = conn.prepareStatement(sql);

		ResultSet rs = ps.executeQuery();

		while (rs.next())
		{
			SLeashes sleashes = new SLeashes();
			
			sleashes.setId( rs.getInt( "ID" ) );
			sleashes.setStandardSize( rs.getString( "standard_size" ) );
			sleashes.setMinWidht( rs.getInt( "min_width" ) );
			sleashes.setMaxWidht( rs.getInt( "max_width" ) );
			
			sleashes.setSizeToDisplay( sizes.get( sleashes.getStandardSize() ) );
			sleashes.setWidhtToDisplay( sleashes.getMinWidht() + " - " + sleashes.getMaxWidht() );
			
			sleashesList.add( sleashes );
		}

		rs.close();
		ps.close();

		return sleashesList;
	}
	
	public SLeashes getSLeashesDetail( String sleashesSize ) throws SQLException
	{
		SLeashes sleashes = new SLeashes();

		String sql = "SELECT * FROM leashes_standard_size where standard_size=?";
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, sleashesSize);

		ResultSet rs = ps.executeQuery();

		while (rs.next())
		{
			sleashes.setId( rs.getInt( "ID" ) );
			sleashes.setStandardSize( rs.getString( "standard_size" ) );
			sleashes.setMinWidht( rs.getInt( "min_width" ) );
			sleashes.setMaxWidht( rs.getInt( "max_width" ) );
			
			sleashes.setSizeToDisplay( sizes.get( sleashes.getStandardSize() ) );
			sleashes.setWidhtToDisplay( sleashes.getMinWidht() + " - " + sleashes.getMaxWidht() );
			sleashes.setSizes( sleashes.getStandardSize() );
		}

		rs.close();
		ps.close();
		
		return sleashes;
	}
	
	public void updateSLeashesDetail( SLeashes sleashes ) throws SQLException
	{
		String sql = "UPDATE leashes_standard_size SET min_width=?, max_width=? " +
				"WHERE id=?";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setInt(1, sleashes.getMinWidht());
		ps.setInt(2, sleashes.getMaxWidht());
		ps.setInt(3, sleashes.getId());

		ps.executeUpdate();
		ps.close();
		
		conn.close();
	}

	public ArrayList<SToothbrush> getSToothbrushAll() throws Exception
	{
		ArrayList<SToothbrush> stToothbrushList = new ArrayList<SToothbrush>();

		String sql = "select * from toothbrush_standard_size";
		PreparedStatement ps = conn.prepareStatement(sql);

		ResultSet rs = ps.executeQuery();

		while (rs.next())
		{
			SToothbrush stToothbrush = new SToothbrush();
			
			stToothbrush.setId( rs.getInt( "ID" ) );
			stToothbrush.setStandardSize( rs.getString( "standard_size" ) );
			stToothbrush.setMinLength( rs.getInt( "min_length" ) );
			stToothbrush.setMaxLength( rs.getInt( "max_length" ) );
			
			stToothbrush.setSizeToDisplay( sizes.get( stToothbrush.getStandardSize() ) );
			stToothbrush.setLengthToDisplay( stToothbrush.getMinLength() + " - " + stToothbrush.getMaxLength() );
			
			stToothbrushList.add( stToothbrush );
		}

		rs.close();
		ps.close();

		return stToothbrushList;
	}
	
	public SToothbrush getSToothbrushDetail( String stToothbrushSize ) throws SQLException
	{
		SToothbrush stToothbrush = new SToothbrush();

		String sql = "SELECT * FROM toothbrush_standard_size where standard_size=?";
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, stToothbrushSize);

		ResultSet rs = ps.executeQuery();

		while (rs.next())
		{
			stToothbrush.setId( rs.getInt( "ID" ) );
			stToothbrush.setStandardSize( rs.getString( "standard_size" ) );
			stToothbrush.setMinLength( rs.getInt( "min_length" ) );
			stToothbrush.setMaxLength( rs.getInt( "max_length" ) );
			
			stToothbrush.setSizeToDisplay( sizes.get( stToothbrush.getStandardSize() ) );
			stToothbrush.setLengthToDisplay( stToothbrush.getMinLength() + " - " + stToothbrush.getMaxLength() );
			stToothbrush.setSizes( stToothbrush.getStandardSize() );
		}

		rs.close();
		ps.close();
		
		return stToothbrush;
	}
	
	public void updateSToothbrushDetail( SToothbrush stToothbrush ) throws SQLException
	{
		String sql = "UPDATE toothbrush_standard_size SET min_length=?, max_length=? " +
				"WHERE id=?";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setInt(1, stToothbrush.getMinLength());
		ps.setInt(2, stToothbrush.getMaxLength());
		ps.setInt(3, stToothbrush.getId());

		ps.executeUpdate();
		ps.close();
		
		conn.close();
	}

	public ArrayList<SToy> getSToyAll() throws Exception
	{
		ArrayList<SToy> stoyList = new ArrayList<SToy>();

		String sql = "select * from toy_standard_size";
		PreparedStatement ps = conn.prepareStatement(sql);

		ResultSet rs = ps.executeQuery();

		while (rs.next())
		{
			SToy stoy = new SToy();
			
			stoy.setId( rs.getInt( "ID" ) );
			stoy.setStandardSize( rs.getString( "standard_size" ) );
			stoy.setType( rs.getInt( "type" ) );
			stoy.setMinDiameter( rs.getInt( "min_diameter" ) );
			stoy.setMaxDiameter( rs.getInt( "max_diameter" ) );
			stoy.setMinWidht( rs.getInt( "min_width" ) );
			stoy.setMaxWidht( rs.getInt( "max_width" ) );
			stoy.setMinLength( rs.getInt( "min_length" ) );
			stoy.setMaxLength( rs.getInt( "max_length" ) );
			stoy.setMinHeight( rs.getInt( "min_height" ) );
			stoy.setMaxHeight( rs.getInt( "max_height" ) );
			
			stoy.setSizes( stoy.getStandardSize() );
			stoy.setTypes( String.valueOf(stoy.getType()) );
			
			stoy.setSizeToDisplay( sizes.get( stoy.getStandardSize() ) );
			stoy.setTypeToDisplay( toyType.get( stoy.getType()) );
			
			if ( stoy.getMinDiameter() == 0 && stoy.getMaxDiameter() == 0 )
			{
				stoy.setDiameterToDisplay( "-" );
			}
			else
			{
				stoy.setDiameterToDisplay( stoy.getMinDiameter() + " - " + stoy.getMaxDiameter() );
			}
			
			if ( stoy.getMinWidht() == 0 && stoy.getMaxWidht() == 0 )
			{
				stoy.setWidhtToDisplay( "-" );
			}
			else
			{
				stoy.setWidhtToDisplay( stoy.getMinWidht() + " - " + stoy.getMaxWidht() );
			}
			
			if ( stoy.getMinLength() == 0 && stoy.getMaxLength() == 0 )
			{
				stoy.setLengthToDisplay( "-" );
			}
			else
			{
				stoy.setLengthToDisplay( stoy.getMinLength() + " - " + stoy.getMaxLength() );
			}
			
			if ( stoy.getMinHeight() == 0 && stoy.getMaxHeight() == 0 )
			{
				stoy.setHeightToDisplay( "-" );
			}
			else
			{
				stoy.setHeightToDisplay( stoy.getMinHeight() + " - " + stoy.getMaxHeight() );
			}
			
			stoyList.add( stoy );
		}

		rs.close();
		ps.close();

		return stoyList;
	}
	
	public SToy getSToyDetail( int type, String size ) throws SQLException
	{
		SToy stoy = new SToy();

		String sql = "SELECT * FROM toy_standard_size where standard_size=? and type=?;";
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, size);
		ps.setInt(2, type);

		ResultSet rs = ps.executeQuery();

		while (rs.next())
		{
			stoy.setId( rs.getInt( "ID" ) );
			stoy.setStandardSize( rs.getString( "standard_size" ) );
			stoy.setType( rs.getInt( "type" ) );
			stoy.setMinDiameter( rs.getInt( "min_diameter" ) );
			stoy.setMaxDiameter( rs.getInt( "max_diameter" ) );
			stoy.setMinWidht( rs.getInt( "min_width" ) );
			stoy.setMaxWidht( rs.getInt( "max_width" ) );
			stoy.setMinLength( rs.getInt( "min_length" ) );
			stoy.setMaxLength( rs.getInt( "max_length" ) );
			stoy.setMinHeight( rs.getInt( "min_height" ) );
			stoy.setMaxHeight( rs.getInt( "max_height" ) );
			
			stoy.setSizes( stoy.getStandardSize() );
			stoy.setTypes( String.valueOf(stoy.getType()) );
			
			stoy.setSizeToDisplay( sizes.get( stoy.getStandardSize() ) );
			stoy.setTypeToDisplay( toyType.get( stoy.getType()) );
			
			if ( stoy.getMinDiameter() == 0 && stoy.getMaxDiameter() == 0 )
			{
				stoy.setDiameterToDisplay( "-" );
			}
			else
			{
				stoy.setDiameterToDisplay( stoy.getMinDiameter() + " - " + stoy.getMaxDiameter() );
			}
			
			if ( stoy.getMinWidht() == 0 && stoy.getMaxWidht() == 0 )
			{
				stoy.setWidhtToDisplay( "-" );
			}
			else
			{
				stoy.setWidhtToDisplay( stoy.getMinWidht() + " - " + stoy.getMaxWidht() );
			}
			
			if ( stoy.getMinLength() == 0 && stoy.getMaxLength() == 0 )
			{
				stoy.setLengthToDisplay( "-" );
			}
			else
			{
				stoy.setLengthToDisplay( stoy.getMinLength() + " - " + stoy.getMaxLength() );
			}
			
			if ( stoy.getMinHeight() == 0 && stoy.getMaxHeight() == 0 )
			{
				stoy.setHeightToDisplay( "-" );
			}
			else
			{
				stoy.setHeightToDisplay( stoy.getMinHeight() + " - " + stoy.getMaxHeight() );
			}
		}

		rs.close();
		ps.close();
		
		return stoy;
	}
	
	public void updateSToyDetail( SToy stoy ) throws SQLException
	{
		if ( stoy.getType() == 1 || stoy.getType() == 3 )
		{
			String sql = "UPDATE toy_standard_size SET min_diameter=?, max_diameter=? " +
					"WHERE id=?";
			
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.setInt(1, stoy.getMinDiameter());
			ps.setInt(2, stoy.getMaxDiameter());
			ps.setInt(3, stoy.getId());

			ps.executeUpdate();
			ps.close();
		}
		else if ( stoy.getType() == 2 )
		{
			String sql = "UPDATE toy_standard_size SET min_length=?, max_length=? " +
					"WHERE id=?";
			
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.setInt(1, stoy.getMinLength());
			ps.setInt(2, stoy.getMaxLength());
			ps.setInt(3, stoy.getId());

			ps.executeUpdate();
			ps.close();
		}
		else if ( stoy.getType() == 4 || stoy.getType() == 5 )
		{
			String sql = "UPDATE kennel_standard_size SET min_width=?, max_width=?, " +
					"min_length=?, max_length=?, min_height=?, max_height=? " +
					"WHERE id=?";
			
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.setInt(1, stoy.getMinWidht());
			ps.setInt(2, stoy.getMaxWidht());
			ps.setInt(3, stoy.getMinLength());
			ps.setInt(4, stoy.getMaxLength());
			ps.setInt(5, stoy.getMinHeight());
			ps.setInt(6, stoy.getMaxHeight());
			ps.setInt(7, stoy.getId());

			ps.executeUpdate();
			ps.close();
		}
		else if ( stoy.getType() == 6 )
		{
			String sql = "UPDATE toy_standard_size SET min_height=?, max_height=? " +
					"WHERE id=?";
			
			PreparedStatement ps = conn.prepareStatement(sql);
			ps.setInt(1, stoy.getMinHeight());
			ps.setInt(2, stoy.getMaxHeight());
			ps.setInt(3, stoy.getId());

			ps.executeUpdate();
			ps.close();
		}
		
		conn.close();
	}

}
